<?php
 // Copyright (C) 2010-2011 Aron Racho <aron@mi-squred.com>
 //
 // This program is free software; you can redistribute it and/or
 // modify it under the terms of the GNU General Public License
 // as published by the Free Software Foundation; either version 2
 // of the License, or (at your option) any later version.
?>
<script language="javascript" src="<?php js_src('list.js') ?>"></script>
<script language="javascript" src="<?php js_src('jQuery.fn.sortElements.js') ?>"></script>

<script type="text/javascript">
    function show_rule(id){
		//alert (id);
		$.get('../super/rules/index.php' +
		'?action=detail!view' +
		'&id='+id,
		function(data){
			$("#info2").html(data);
			$("#info2").show();
			$("#info").hide();
		});		
	}
	
	function add_new(){
	
	$.get('../super/rules/index.php' +
		'?action=edit!summary',
		function(data){
			$("#info2").html(data);
			$("#info2").show();
			$("#info").hide();
		});	
	}
	
	var list = new list_rules();
    list.init();

	
	$.get('../super/rules/index.php' +
		'?action=browse!getrows',
		function(responseData) {
		var response='';
			var msg = responseData.split("{");
			for( i=1; i< msg.length ;i++){
				var struc = "";
				var myrow = msg[i].substring(0, msg[i].length-2);
				
				var mydata = myrow.split(",");
				var sep1 = mydata[0].indexOf(":");
				var sep2 = mydata[1].indexOf(":");
				var sep3 = mydata[2].indexOf(":");
				
				struc = "<div class=\"rule_row data\">";
					struc +="<span class=\"rule_title\">";
							struc +="<a onclick=\"show_rule('"+ mydata[2].substring(sep3 + 2, mydata[2].length-1) +"');\" href=\"#\">";
								struc += mydata[0].substring(sep1 + 2, mydata[0].length-1);
							struc += "</a>";
					struc += "</span>";
					
					struc +="<span class=\"rule_type\">";
						struc +="<a onclick=\"top.restoreSession()\" href=\"#\">";
							struc += mydata[1].substring(sep2 + 2, mydata[1].length-1);
						struc += "</a>";
					struc += "</span>";
				struc +="</div>";
				$(".rule_container").append(struc);
			}
		});
	
</script>

<table class="header">
  <tr>
        <td class="title"><?php echo out( xl( 'Rules Configuration' ) ); ?></td>
        <td>
            <!--a href="#" class="iframe_medium css_button" onclick="top.restoreSession();add_new();">
                <span><?php echo out( xl( 'Add new' ) ); ?></span>
            </a-->
			<input type='button' value='<?php echo out( xl( 'Add new' ) ); ?>' onclick='add_new();'>
			</input>
        </td>
  </tr>
</table>

<div class="rule_container text">
    <div class="rule_row header">
        <span class="rule_title header_title"><?php echo out( xl( 'Name' ) ); ?></span>
        <span class="rule_type header_type"><?php echo out( xl( 'Type' ) ); ?></span>
    </div>
</div>


<!-- template -->
<div class="rule_row data template">
    <span class="rule_title"><a href="index.php?action=detail!view" onclick="top.restoreSession()"></a></span>
    <span class="rule_type"><a href="index.php?action=detail!view" onclick="top.restoreSession()"></a></span>
</div>

